//
//  MainViewController.m
//  HeadTabView
//
//  Created by 吴浪 on 15/12/23.
//  Copyright © 2015年 吴浪. All rights reserved.
//

#import "MainViewController.h"
#import "Masonry.h"
#import "HeadBouncesView.h"

#define HEADVIEW_HEIGHT 120.0
#define HEADVIEW_WIDTH ([UIScreen mainScreen].bounds.size.width)

@interface MainViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, weak) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@property (nonatomic, strong) HeadBouncesView *headView;
@end

@implementation MainViewController

//- (UIImageView *)headView {
//    if (_headView == nil) {
//        UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, HEADVIEW_WIDTH, HEADVIEW_HEIGHT)];
//        view.image = [UIImage imageNamed:@"banner004"];
//        view.contentMode = UIViewContentModeScaleAspectFill;
//        view.layer.masksToBounds = YES;
//        _headView = view;
//    }
//    return _headView;
//}

- (NSMutableArray *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
        for (int i = 0; i < 10; i++) {
            [_dataArray addObject:@(i)];
        }
    }
    return _dataArray;
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.contentInset = UIEdgeInsetsMake(HEADVIEW_HEIGHT, 0, 0, 0);
        [self.view addSubview:tableView];
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource, UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.textLabel.text = [self.dataArray[indexPath.row] stringValue];
    return cell;
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    NSLog(@"%@", NSStringFromCGPoint(scrollView.contentOffset));
//    CGFloat y = scrollView.contentOffset.y;
//    if (y < -HEADVIEW_HEIGHT) {
//        CGRect rect = self.headView.frame;
//        rect.size.height = -y;
//        rect.origin.y = y;
//        self.headView.frame = rect;
//    }
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView.backgroundColor = [UIColor whiteColor];
//    [self.tableView addSubview:self.headView];
    self.headView = [HeadBouncesView headBouncesViewWithFrame:CGRectMake(0, 0, HEADVIEW_WIDTH, HEADVIEW_HEIGHT) imageName:@"banner004" scrollView:self.tableView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
